﻿#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution
{
public:
    // 942. 增减字符串匹配
    vector<int> diStringMatch(string s)
    {
        int left = 0, right = s.size();
        vector<int> ret;
        for (int i = 0; i < s.size(); ++i)
        {
            if (s[i] == 'I')
                ret.push_back(left++);
            else
                ret.push_back(right--);
        }
        ret.push_back(left);
        return ret;
    }

    // 455. 分发饼干
    int findContentChildren(vector<int>& g, vector<int>& s)
    {
        int m = g.size(), n = s.size();
        sort(g.begin(), g.end());
        sort(s.begin(), s.end());

        int ret = 0;
        for (int i = 0, j = 0; i < m && j < n; ++i, ++j)
        {
            while (j < n && s[j] < g[i])
                ++j;
            if (j < n)
                ++ret;
        }
        return ret;
    }
};

int main()
{
    /*string s = "IDID";
    vector<int> ret = Solution().diStringMatch(s);
    for (auto x : ret)
        cout << x << " ";
    cout << endl;*/

    vector<int> g{ 1,2,3 };
    vector<int> s{ 1,1 };
    cout << Solution().findContentChildren(g, s) << endl;

    return 0;
}